package com.sysware.mq.example;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

class Publisher {

	public static void main(String[] args) throws JMSException {
		
		// 创建连接工厂
		ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(PropertiesUtil.getValue("ACTIVEMQ_URL"));
		// 创建连接
		Connection connection = activeMQConnectionFactory.createConnection();
		// 打开连接
		connection.start();
		// 创建会话
		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		// 创建队列目标
		Destination destination = session.createQueue(PropertiesUtil.getValue("QUEUE_NAME"));
		// 创建一个生产者
		javax.jms.MessageProducer producer = session.createProducer(destination);
		// 创建模拟100个消息
		for (int i = 1; i <= 100; i++) {
			TextMessage message = session.createTextMessage("我发送message:" + i);
			// 发送消息
			producer.send(message);
			// 在本地打印消息
			System.out.println("我现在发的消息是：" + message.getText());
		}
		// 关闭连接
		connection.close();
	}
}